package com.kapcb.mvc.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;

/**
 * <a>Title: ServiceRunStatusListener </a>
 * <a>Author: kapcb <a>
 * <a>Description: 服务运行状态监听 <a>
 *
 * @author Kpacb
 * @version 1.0
 * @date 2024/4/24 9:47
 * @since 1.0
 */
@Slf4j
public class ServiceRunStatusListener implements ApplicationListener<ApplicationEvent> {

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ContextRefreshedEvent) {
            log.info("Spring 容器完成初始化容器刷新");
        }
        if (event instanceof ContextStartedEvent) {
            log.info("应用服务启动成功，需要在代码动态添加监听器才可捕获");
        }
        if (event instanceof ContextStoppedEvent) {
            log.info("应用停止...");
        }
        if (event instanceof ContextClosedEvent) {
            log.info("应用关闭...");

        }
    }

}
